from django.db import models

from django.contrib.auth.models import User 
from django.contrib.contenttypes.models import ContentType
from ckeditor_uploader.fields import RichTextUploadingField

from read_count.models import ReadNumExpandMethod



# Create your models here.
class BlogType(models.Model):
    type_name = models.CharField(max_length=15)
    
    def __str__(self):
        return self.type_name

class Blog(models.Model,ReadNumExpandMethod):
    title = models.CharField(max_length=50)
    blog_type = models.ForeignKey(BlogType, on_delete = models.DO_NOTHING)
    content = RichTextUploadingField()
    author = models.ForeignKey(User,on_delete =models.DO_NOTHING)
    
    #read_num = models.IntegerField(default=0)
    
    created_time= models.DateTimeField(auto_now_add=True)
    last_updated_time = models.DateTimeField(auto_now = True)



    def __str__(self):
        return "<Blog:%s>" %self.title
    
    #分页 排序
    class Meta:
        ordering = ['-created_time']
'''        
class ReadaNum(models.Model):
    read_num = models.IntegerField(default=0)
    blog = models.OneToOneField(Blog,on_delete=models.DO_NOTHING)
'''